<template>
  <view class="wrap" v-if="showPage">
    <view class="status" v-if="status == 2">审核不通过，{{ opt.reason }}</view>
    <view class="status" v-if="status == 0">审核中</view>
    <view class="card">
      <view class="name">上传名片</view>
      <view class="icon" @click="chooseImage">
        <image :src="setUrl(opt.card_image)" mode="aspectFill" class="img" v-if="opt.card_image"></image>
        <image src="../../static/card.png" class="img" v-else></image>
      </view>
    </view>
    <view class="list">
      <view class="item">
        <view class="left">任职机构</view>
        <view class="right">
          <uv-input placeholder="请填写任职机构名称" border="none" v-model="opt.organ" fontSize='32rpx' color='#333' placeholderStyle='font-size: 32rpx;color: #B8B8B8'></uv-input>
        </view>
      </view>
      <view class="item">
        <view class="left">职位</view>
        <view class="right">
          <uv-input placeholder="请填写职位名称" border="none" v-model="opt.job" fontSize='32rpx' color='#333' placeholderStyle='font-size: 32rpx;color: #B8B8B8'></uv-input>
        </view>
      </view>
      <view class="item">
        <view class="left">身份</view>
        <view class="right" @click="openIdent">
          <uv-input placeholder="请选择" border="none" v-model="identList[opt.identity]" readonly fontSize='32rpx' color='#333' suffixIcon='arrow-down' placeholderStyle='font-size: 32rpx;color: #B8B8B8'></uv-input>
        </view>
      </view>
    </view>
    
    <view class="footer">
      <template v-if="status == null || status == 2">
        <button class="btn" hover-class="none" @click="keyUp">提交审核</button>
      </template>
      <template v-else>
        <button class="btn" hover-class="none" disabled>待审核</button>
      </template>
      <uv-safe-bottom></uv-safe-bottom>
    </view>
    <view class="safe"></view>
    <uv-safe-bottom></uv-safe-bottom>
    
    <uv-picker ref="picker" :columns="columns" keyName="label" confirmColor='#E43222' @confirm="pickConfirm"></uv-picker>
    
    <action ref="actionPhoto" :size="{ width: 328, height: 220 }" @click="getImageUrl"></action>
  </view>
</template>

<script setup>
import { ref } from 'vue';
import { post } from '@/api';
import { setUrl, choose, toast } from '@/common';
import { onLoad } from '@dcloudio/uni-app';

const actionPhoto = ref(null);
const identList = ref({
  1:'公募基金',2:'险资机构',3:'券商自营及资产管理',4:'证券投资类私募',5:'股权投资类私募',6:'创业投资类私募',7:'其他类私募',8:'未备案投资私募',9:'产业资本',10:'QFII和QFII机构',11:'其他机构投资者',12:'卖方分析师',13:'上市公司高管',14:'券商投资顾问',15:'财经记者',16:'高净值个人',17:'私董会成员',18:'公募基金与险资机构免费',19:'公募险资和私董会成员不受名额限制'
});
const columns = [
  [
    { id: 1, label: '公募基金' },{ id: 2, label: '险资机构' },{ id: 3, label: '券商自营及资产管理' },{ id: 4, label: '证券投资类私募' },{ id: 5, label: '股权投资类私募' },{ id: 6, label: '创业投资类私募' },{ id: 7, label: '其他类私募' },{ id: 8, label: '未备案投资私募' },{ id: 9, label: '产业资本' },{ id: 10, label: 'QFII和QFII机构' },{ id: 11, label: '其他机构投资者' },{ id: 12, label: '卖方分析师' },{ id: 13, label: '上市公司高管' },{ id: 14, label: '券商投资顾问' },{ id: 15, label: '财经记者' },{ id: 16, label: '高净值个人' },{ id: 17, label: '私董会成员' },{ id: 18, label: '公募基金与险资机构免费' },{ id: 19, label: '公募险资和私董会成员不受名额限制' },
  ]
];
const picker = ref(null);

let showPage = ref(false);
let status = ref(null);
let opt = ref({
  card_image: '',
  organ: '',
  job: '',
  identity: ''
});

onLoad(() => {
  getCert();
})

function keyUp(){
  if(!opt.value.card_image) return toast('请上传名片');
  if(!opt.value.organ) return toast('请输入任职机构');
  if(!opt.value.job) return toast('请输入职位');
  if(!opt.value.identity) return toast('请选择身份');
  
  const params = {
    card_image: opt.value.card_image,
    organ: opt.value.organ,
    job: opt.value.job,
    identity: opt.value.identity
  }
  post('api/user/userIdentityAuth', params).then(res => {
    if(res.code == 1){
      const data = res.data;
      toast('提交成功');
      getCert();
    }
  })
}
function getCert(){
  post('api/user/getIdentityAuthInfo').then(res => {
    if(res.code == 1){
      const data = res.data;
      if(data){
        if(data.examine_status == 1){
          
        }else{
          status.value = data.examine_status;
          opt.value = data;
          showPage.value = true;
        }
      }else{
        showPage.value = true;
      }
    }
  })
}
function chooseImage(){
  actionPhoto.value.open();
}
function getImageUrl(url){
  list.value.push(url);
}
function openIdent(){
  picker.value.open();
}
function pickConfirm(e){
  const value = e.value[0];
  opt.value.identity = value.id;
}
</script>

<style lang="scss" scoped>
  .safe{
    width: 100%;
    height: 208rpx;
  }
  .footer{
    width: 100%;
    background-color: #fff;
    padding: 0 30rpx;
    padding-top: 16rpx;
    padding-bottom: 30rpx;
    position: fixed;
    left: 0;
    bottom: 0;
    .btn{
      font-size: 34rpx;
    }
  }
  .status{
    width: 100%;
    height: 80rpx;
    line-height: 80rpx;
    background: #FFEDEB;
    font-weight: 400;
    font-size: 28rpx;
    color: #E43222;
    text-align: center;
  }
  .card{
    padding: 30rpx;
    background-color: #fff;
    .icon{
      width: 328rpx;
      height: 220rpx;
      font-size: 0;
    }
    .name{
      font-weight: 500;
      font-size: 32rpx;
      color: #2B2B2B;
      padding-bottom: 20rpx;
    }
  }
  .list{
    margin-top: 20rpx;
    padding: 0 30rpx;
    background-color: #fff;
    .item{
      width: 100%;
      height: 120rpx;
      display: flex;
      align-items: center;
      .right{
        flex: 1;
        width: 0;
      }
      .left{
        width: 160rpx;
        font-weight: 400;
        font-size: 32rpx;
        color: #2B2B2B;
      }
    }
  }
  .wrap{
    width: 100%;
    min-height: 100vh;
    background-color: #F5F5F5;
  }
</style>